package ch18;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.*;

public class Util {
	public static String[] createGiantArray() {
		boolean toFile = false;
		boolean fromFile = !toFile;
		String filePath = "/home/ryan/Desktop/dictionary";
		if (toFile) {
			String[] arr = {};

			Writer output;
			try {
				output = new BufferedWriter(new FileWriter(filePath));
				for (String s : arr) {
					output.write(s);
					output.write('\n');
				}
				output.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		String[] arr = null;
		if (fromFile) {
			Scanner input;
			try {
				input = new Scanner(new FileReader(filePath));
				int n = Integer.parseInt(input.nextLine());
				arr = new String[n];
				int i = 0;
				while (input.hasNext()) {
					String s = input.nextLine();
					arr[i] = s;
					i++;
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		List<String> list = new ArrayList<String>();
		int k = 10;
		for (int i = 0; i < arr.length; i++) {
			int n = (int) (Math.random() * k);
			String s = arr[i];
			for (int j = 0; j < n; j++) {
				int index = (int) (Math.random() *
				// arr.length
				i);
				s += arr[index];
			}
			list.add(s);
			list.add(arr[i]);
		}
		String[] ar = new String[list.size()];
		ar = list.toArray(ar);
		return ar;
	}

	public static String[] getBigArray() {
		String filePath = "/home/ryan/Desktop/dictionary";
		Scanner input;
		String[] arr = null;
		try {
			input = new Scanner(new FileReader(filePath));
			int n = Integer.parseInt(input.nextLine());
			arr = new String[n];
			int i = 0;
			while (input.hasNext()) {
				String s = input.nextLine().toLowerCase();
				arr[i] = s;
				i++;
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return arr;
	}
}